<?php

Raise::load('core.RaiseUrlRoute');

/**
 * TestCoreRaiseUrlRoute class
 * Testing unit of 'phpraise/core/RaiseUrlRoute.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseUrlRoute extends RaiseTest {
    
    public static function testClass(){
        self::assertClassExists('RaiseUrlRoute');
        self::assertClassExtends('RaiseUrlRoute', 'RaiseHelper');
        self::assertClassImplements('RaiseUrlRoute', 'IRaiseInitializable');
        self::assertClassMethod('RaiseUrlRoute', 'routes');
        self::assertClassMethod('RaiseUrlRoute', 'route');
        self::assertClassMethod('RaiseUrlRoute', 'rewrite');
        self::assertObjectClass(RaiseUrlRoute::routes(), 'RaiseCollection');
    }

    public static function testObject(){
        $r = new RaiseUrlRoute('article/$id$-$title$', 'ArticlePage', array('$id$' => '[0-9]'));
        self::assertObjectClass($r, 'RaiseUrlRoute');
        RaiseUrlRoute::routes()->add('articleLink', $r);
        $url = RaiseUrlRoute::route('articleLink', array('id' => 24, 'title' => 'test-article'));
        self::assertType($url, 'string');
        self::assertStrictEqual($url, 'article/24-test-article');
    }

    public static function testObject2(){
        $r = new RaiseUrlRoute('member/$name$', 'MemberPage', array('$id$' => '[a-zA-Z0-9\-\_]'));
        self::assertObjectClass($r, 'RaiseUrlRoute');
        RaiseUrlRoute::routes()->add('memberLink', $r);
        $url = RaiseUrlRoute::route('memberLink', array('name' => 'testUserName'));
        self::assertType($url, 'string');
        self::assertStrictEqual($url, 'member/testUserName');
    }

    public static function testFetchInvalid(){
        try{
            $route = RaiseUrlRoute::route('non-exist3entROUT3');
            self::addError('Fetch invalid operation failed.');
        }catch(Exception $e){
            self::assert($e);
        }
    }

}
